// @ts-ignore
import {request} from 'umi';
import type {RoleListItem, RoleListParams} from './data.d';
import {updateRoleMenuListParams} from "./data.d";

/**
 * 查询角色信息
 * @param params
 */
export async function queryRoleList(params: RoleListParams) {
  return request<RoleListItem>('/api/tpl/role/queryRoleList', {
    method: 'POST',
    data: {
      ...params,
    },
  });
}

/**
 * 删除角色信息
 * @param ids
 */
export async function removeRole(ids: number[]) {
  return request('/api/tpl/role/deleteRole', {
    method: 'DELETE',
    data: {
      ids: ids
    },
  });
}

/**
 * 添加角色信息
 * @param params
 */
export async function addRole(params: RoleListItem) {
  return request('/api/tpl/role/saveRole', {
    method: 'POST',
    data: {
      ...params,
    },
  });
}

/**
 * 更新角色信息
 * @param params
 */
export async function updateRole(params: RoleListItem) {
  return request('/api/tpl/role/updateRole', {
    method: 'PUT',
    data: {
      ...params,
    },
  });
}

/**
 * @description: 查询角色菜单
 * @params {ids} number[]
 * @return {Promise}
 */
export async function queryRoleMenuList(params: { roleId: number }) {
  return request('/api/tpl/role/queryRoleMenuList?roleId=' + params.roleId, {
    method: 'GET',
    // data: {
    //   ...params,
    // },
  });
}

/**
 * @description: 更新角色菜单
 * @params {ids} number[]
 * @return {Promise}
 */
export async function updateRoleMenuList(params: updateRoleMenuListParams) {
  return request('/api/tpl/role/updateRoleMenuList', {
    method: 'POST',
    data: {
      ...params,
    },
  });
}
